package cn.com.nes.site.action.crm;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.nes.common.util.DBUtils;
import cn.com.nes.site.entity.DataReq;
import cn.com.nes.site.entity.DataRes;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.module.service.crm.AnalysisService;

@Controller("analysis")
@RequestMapping("/analysis")
public class AnalysisAction  {
	@Resource
    private AnalysisService service;
	
	/**
	 * 获取线索分析数据
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(method = {RequestMethod.POST}, value = "/getClueStatistics")
	public @ResponseBody PageData getClueStatistics(HttpServletRequest request, HttpServletResponse response) {
		DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
		PageData res = new PageData() ;
		if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
		DataReq req = req_Status.getReq();
        res = service.getClueStatistics(req) ;
        return res;
	}
	
	/**
	 * 获取流量来源
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(method = {RequestMethod.POST}, value = "/getClueSources")
	public @ResponseBody PageData getClueSources(HttpServletRequest request, HttpServletResponse response) {
		DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
		PageData res = new PageData() ;
		if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
		DataReq req = req_Status.getReq();
        res = service.getClueSources(req) ;
        return res;
	}
	
	/**
	 * 获取线索阶段
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(method = {RequestMethod.POST}, value = "/getClueStagesStatistics")
	public @ResponseBody PageData getClueStagesStatistics(HttpServletRequest request, HttpServletResponse response) {
		DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
		PageData res = new PageData() ;
		if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
		DataReq req = req_Status.getReq();
        res = service.getClueStagesStatistics(req) ;
        return res;
	}
	
	/**
	 * 获取线索区域分布排行和地图数据
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(method = {RequestMethod.POST}, value = "/getClueDistributionStatistics")
	public @ResponseBody PageData getClueDistributionStatistics(HttpServletRequest request, HttpServletResponse response) {
		DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
		PageData res = new PageData() ;
		if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
		DataReq req = req_Status.getReq();
        res = service.getClueDistributionStatistics(req) ;
        return res;
	}
	
	/**
	 * 线索属性统计，包括：入池方式、线索类型、线索状态
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(method = {RequestMethod.POST}, value = "/getClueProperiesStatistics")
	public @ResponseBody PageData getClueProperiesStatistics(HttpServletRequest request, HttpServletResponse response) {
		DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
		PageData res = new PageData() ;
		if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
		DataReq req = req_Status.getReq();
        res = service.getClueProperiesStatistics(req) ;
        return res;
	}
	
	/**
	 * 获取线索按照时间分布折线图数据
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(method = {RequestMethod.POST}, value = "/getClueStateDateSerialStatistics")
	public @ResponseBody PageData getClueStateDateSerialStatistics(HttpServletRequest request, HttpServletResponse response) {
		DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
		PageData res = new PageData() ;
		if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
		DataReq req = req_Status.getReq();
        res = service.getClueStateDateSerialStatistics(req) ;
        return res;
	}
	
	/**
	 * 线索响应统计，包括：线索响应速度、线索转商机时长
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(method = {RequestMethod.POST}, value = "/getClueReactionStatistics")
	public @ResponseBody PageData getClueReactionStatistics(HttpServletRequest request, HttpServletResponse response) {
		DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
		PageData res = new PageData() ;
		if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
		DataReq req = req_Status.getReq();
        res = service.getClueReactionStatistics(req) ;
        return res;
	}
	
	/**
	 * 最近三个月的员工线索跟进信息列表
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(method = {RequestMethod.POST}, value = "/getEmployeeFollowUpList")
	public @ResponseBody PageData getEmployeeFollowUpList(HttpServletRequest request, HttpServletResponse response) {
		DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
		PageData res = new PageData() ;
		if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
		DataReq req = req_Status.getReq();
        res = service.getEmployeeFollowUpList(req) ;
        return res;
	}
	
}
